﻿@using XXS.Common.Paginate;
@model IPaginate<KTD.Web.Models.VD.HouseListVD>
<style>
    .saveResult .layui-form-label {
        width: 120px;
    }
</style>

<div class="x-body" id="box">
    <div class="layui-row">
        <form class="layui-form ">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    @Html.TextBox("Query", null, new { @class = "layui-input", placeholder = "关键字" })
                    <input type="hidden" id="Channel" name="Channel" value="@ViewBag.Channel" />
                </div>

                @if (ViewBag.Channel == "sale")
                {
                    <div class="layui-input-inline">
                        @Html.DropDownList("LetWay", ViewBag.saleTypeList as IEnumerable<SelectListItem>, new { @class = "layui-input" })
                    </div>
                }
                @if (ViewBag.Channel == "sale")
                {
                    <div class="layui-input-inline">
                        @Html.DropDownList("HouseType", ViewBag.saleTypes as IEnumerable<SelectListItem>, new { @class = "layui-input" })
                    </div>
                }
                else if (ViewBag.Channel == "new")
                {
                    <div class="layui-input-inline">
                        @Html.DropDownList("HouseType", ViewBag.newTypes as IEnumerable<SelectListItem>, new { @class = "layui-input" })
                    </div>
                }
                <div class="layui-input-inline">
                    @Html.DropDownList("Status", ViewBag.statusList as IEnumerable<SelectListItem>, new { @class = "layui-input" })
                </div>
                <div class="layui-input-inline">
                    @Html.DropDownList("Order", ViewBag.orderList as IEnumerable<SelectListItem>, new { @class = "layui-input" })
                </div>
                <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </form>
    </div>

    <xblock style="height:50px;">
        <button class="layui-btn" id="addBtn"><i class="layui-icon"></i>添加</button>

        <span class="x-right" style="line-height:40px">共有数据：@Model.SourceCount 条</span>
    </xblock>
    @if (ViewBag.Channel == "sale")
    {
        <table class="layui-table">
            <thead>
                <tr>
                    <th style="width:200px;">租售名称</th>
                    <th>区域</th>
                    <th>房源类型</th>
                    <th>付款方式</th>
                    <th>房源租金</th>
                    <th>佣金</th>
                    <th>租/售</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.PageData)
                {
                    <tr>
                        <td>@item.title</td>
                        <td>@item.areaname</td>
                        <td>@item.source</td>
                        <td>@item.payway</td>
                        <td>@item.money</td>
                        <td>@item.fxmoney</td>
                        <td>@(item.letway == "1" ? "租" : "售")</td>
                        <td>@item.status</td>
                        <td class="td-manage">
                            <a title="编辑" onclick="update(this,'@item.Id')" href="javascript:;">
                                <i class="icon iconfont">
                                    &#xe6ab;
                                </i>
                            </a>

                            <a title="删除" onclick="member_del(this,'@item.Id')" href="javascript:;">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                }

            </tbody>
        </table>

    }
    else
    {
        <table class="layui-table">
            <thead>
                <tr>
                    <th style="width:200px;">楼盘名称</th>
                    <th>区域</th>
                    <th>开发商</th>
                    <th>地址</th>
                    <th>均价</th>
                    <th>状态</th>
                    <th>热度</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.PageData)
                {
                <tr>
                    <td>@item.housename</td>
                    <td style="width:80px;">@item.areaname</td>
                    <td>@item.companyname</td>
                    <td>@item.houseaddress</td>
                    <td style="width:80px;">@item.houseprice</td>
                    <td>@item.status</td>
                    <td style="width:80px;">@item.Hot</td>
                    <td class="td-manage">
                        <a title="编辑" onclick="update(this,'@item.Id')" href="javascript:;">
                            <i class="icon iconfont">
                                &#xe6ab;
                            </i>
                        </a>

                        <a title="删除" onclick="member_del(this,'@item.Id')" href="javascript:;">
                            <i class="layui-icon">&#xe640;</i>
                        </a>
                    </td>
                </tr>
                }

            </tbody>
        </table>
    }
    @{
        Html.RenderPartial("_paginate", Model);
    }



</div>


@section scripts{
    <script>
        /*删除*/
        function member_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                 $.ajax({
                     url: '/House/Delete',
                        type: 'post',
                        data: {
                            Id:id,
                        },
                        dataType: 'json',
                        success: function (res) {
                            if (res.success) {

                               $(obj).parents("tr").remove();
                               layer.msg('已删除!', { icon: 1, time: 1000 });
                            }
                            else {
                                layer.msg('删除失败，' + res.msg, { icon: 2, time: 5000 });
                            }

                        }
                    });
                });
        }


        function update(obj, id) {
            window.location.href = "/House/Update/" + id
        }
        $(function () {
            $("#addBtn").click(function () {
                //var win = layer.open({
                //    type: 2,
                //    skin: 'layui-layer-rim', //加上边框
                //    area: ['500px', '500px'], //宽高
                //    content: "/Area/Create" //弹出编辑框
                //});
                window.location.href="/House/Create?Channel=@ViewBag.Channel"
            });
        });

    </script>
}